using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;


using Microsoft.ConnectionEngine.Registers.Core.ServiceProvider.Common;
using Microsoft.ConnectionEngine.Registers.Core.ServiceProvider.Common.DataSets;

using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Configuration;

namespace Microsoft.ConnectionEngine.Registers.Core.ServiceProvider.DataAccess
{
    public class PoolServiceProviderType
    {

        #region Get/Search Methods
        [CLSCompliant(false)]
        public static dsPoolServiceProviderType PoolServiceProviderTypeSearch(string poolID, string serviceProviderTypeID)
        {
            dsPoolServiceProviderType ds = new dsPoolServiceProviderType();
            string SQL = "PoolServiceProviderTypeSearch";

            Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());
            ds.PoolServiceProviderType.Load(db.ExecuteReader(SQL, poolID, serviceProviderTypeID), LoadOption.OverwriteChanges);

            return ds;
        }


        /// <summary>
        /// Returns true if a PoolServiceProviderType row exists
        /// </summary>
        /// <param name="poolid"></param>
        /// <param name="serviceprovidertypeid"></param>
        /// <returns>True if successful</returns>
        public static bool PoolServiceProviderTypeExists(string poolID, string serviceProviderTypeID)
        {
            bool result = false;
            string SQL = "PoolServiceProviderTypeExists";

            Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());
            if (Convert.ToInt32(db.ExecuteScalar(SQL, poolID, serviceProviderTypeID)) > 0)
                result = true;

            return result;
        }

        #endregion

        #region Insert Methods

        /// <summary>
        /// Inserts a new PoolServiceProviderType
        /// </summary>
        /// <param name="poolid"></param>
        /// <param name="serviceprovidertypeid"></param>
        /// <returns>A new ID if successful, otherwise empty string</returns>
        public static bool PoolServiceProviderTypeInsert(string poolID, string serviceProviderTypeID)
        {
            bool result = true;
            string SQL = "PoolServiceProviderTypeInsert";

            Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());
            if (db.ExecuteNonQuery(SQL, poolID, serviceProviderTypeID) <= 0)
                result = false;

            return result;
        }

        #endregion

        #region Delete Methods

        /// <summary>
        /// Deletes a PoolServiceProviderType
        /// </summary>
        /// <param name="poolid"></param>
        /// <param name="serviceprovidertypeid"></param>
        /// <returns>True if successful</returns>
        public static bool PoolServiceProviderTypeDelete(string poolID, string serviceProviderTypeID)
        {
            bool result = true;
            string SQL = "PoolServiceProviderTypeDelete";

            Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());
            if (db.ExecuteNonQuery(SQL, poolID, serviceProviderTypeID) <= 0)
                result = false;

            return result;
        }


        /// <summary>
        /// Deletes all PoolServiceProviderType records belonging of a specific ServiceProviderType
        /// </summary>
        /// <param name="serviceprovidertypeid"></param>
        /// <returns>True if successful</returns>
        public static bool PoolServiceProviderTypeDeleteByServiceProviderTypeID(string serviceProviderTypeID)
        {
            bool result = true;
            string SQL = "PoolServiceProviderTypeDeleteByServiceProviderTypeID";

            Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());
            db.ExecuteNonQuery(SQL, serviceProviderTypeID);                

            return result;
        }


        /// <summary>
        /// Deletes all PoolServiceProviderType records belonging to a specific Pool
        /// </summary>
        /// <param name="poolid">The ID of the parent Pool</param>
        /// <returns>True if successful</returns>
        public static bool PoolServiceProviderTypeDeleteByPoolID(string poolID)
        {
            bool result = true;
            string SQL = "PoolServiceProviderTypeDeleteByPoolID";

            Database db = DatabaseFactory.CreateDatabase(DataAccessHelper.GetDefaultConnectionStringName());
            db.ExecuteNonQuery(SQL, poolID);                

            return result;
        }

        #endregion

    }
}
